package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrderTop10DTO;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /**
     * 取消订单
     * @param orders
     */
    @Select("update orders set status = #{status} where id = #{id}")
    void cancelOrder(Orders orders);

    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    @Update("update orders set pay_status = 5 where id = 9")
    void paySuccess();

    /**
     * 客户催单
     * @param id
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);


    /**
     * 获取当天营业额的总数
     * @return
     * @param map
     */
    Double getAmountSumByTime(Map map);

    /**
     * 查询销量top10的菜品
     * @param map
     */
    List<OrderTop10DTO> getSaleTop10(Map map);

    /**
     * 根据动态条件统计订单数量
     */
    Integer countByMap(Map map);


    /**
     * 历史订单查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> getHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 管理端订单取消
     * @param ordersCancelDTO
     */
    @Update("update orders set cancel_reason = #{cancelReason},status = 6 where id = #{id}")
    void cancelOrderAdmin(OrdersCancelDTO ordersCancelDTO);

    /**
     * 待派送数量
     */
    @Select("select count(id) from orders where status = #{sconfirmedtatus}")
    Integer getConfirmed(Integer confirmed);

    /**
     * 派送中数量
     * @return
     */
    @Select("select count(id) from orders where status = #{deliveryInProgress}")
    Integer getDeliveryInProgress(Integer deliveryInProgress);

    /**
     * 待接单数量
     * @param toBeConfirmed
     * @return
     */
    @Select("select count(id) from orders where status = #{toBeConfirmed}")
    Integer getToBeConfirmed(Integer toBeConfirmed);

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> conditionSearchOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 派送订单
     * @param orders
     */
    @Update("update orders set status = #{status} where id = #{id}")
    void doDelivery(Orders orders);

    /**
     * 完成订单
     * @param orders
     */
    @Update("update orders set status = #{status} where id = #{id}")
    void completeOrder(Orders orders);
}
